<template>
  <div class="app-container">
    <el-row :gutter="20">
      <!--订单数据-->
      <el-col :span="24" :xs="24">

        <!-- 搜索 -->
        <template>
          <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="70px">
            <el-form-item label="订单编号" prop="orderNo">
              <el-input
                v-model="queryParams.orderNo"
                placeholder="请输入订单编号"
                clearable
                style="width: 240px"
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="服务项目" prop="projectId">
              <el-select
                v-model="queryParams.projectId"
                placeholder="服务项目"
                clearable
                style="width: 240px"
              >
                <el-option
                  v-for="dict in projectList"
                  :key="dict.projectId"
                  :label="dict.projectTitle"
                  :value="dict.projectId"
                />
              </el-select>
            </el-form-item>
            <el-form-item label="店员等级" prop="levelId">
              <el-select
                v-model="queryParams.levelId"
                placeholder="店员等级"
                clearable
                style="width: 240px"
              >
                <el-option
                  v-for="dict in levelList"
                  :key="dict.levelId"
                  :label="dict.levelTitle"
                  :value="dict.levelId"
                />
              </el-select>
            </el-form-item>
            <el-form-item label="规格单位" prop="unitId">
              <el-select
                v-model="queryParams.unitId"
                placeholder="规格单位"
                clearable
                style="width: 240px"
              >
                <el-option
                  v-for="dict in unitList"
                  :key="dict.unitId"
                  :label="dict.unitTitle"
                  :value="dict.unitId"
                />
              </el-select>
            </el-form-item>
            <el-form-item label="排除已接" prop="isExclude">
              <el-select
                v-model="queryParams.isExclude"
                placeholder="排除已接"
                clearable
                style="width: 240px"
              >
                <el-option
                  v-for="dict in dict.type.sys_yes_no"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                />
              </el-select>
            </el-form-item>
            <el-form-item label="是否分销" prop="isDistribution">
              <el-select
                v-model="queryParams.isDistribution"
                placeholder="是否分销"
                clearable
                style="width: 240px"
              >
                <el-option
                  v-for="dict in dict.type.sys_yes_no"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                />
              </el-select>
            </el-form-item>
            <el-form-item label="接单类型" prop="acceptType">
              <el-select
                v-model="queryParams.acceptType"
                placeholder="接单类型"
                clearable
                style="width: 240px"
              >
                <el-option
                  v-for="dict in dict.type.app_accept_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                />
              </el-select>
            </el-form-item>
            <el-form-item label="交易状态" prop="payStatus">
              <el-select
                v-model="queryParams.payStatus"
                placeholder="交易状态"
                clearable
                style="width: 240px"
              >
                <el-option
                  v-for="dict in dict.type.app_pay_status"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                />
              </el-select>
            </el-form-item>
            <el-form-item label="服务状态" prop="status">
              <el-select
                v-model="queryParams.status"
                placeholder="服务状态"
                clearable
                style="width: 240px"
              >
                <el-option
                  v-for="dict in dict.type.app_order_status"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                />
              </el-select>
            </el-form-item>
            <el-form-item label="店铺ID" prop="shopId" v-if="$store.getters && $store.getters.admin">
              <el-input
                v-model="queryParams.shopId"
                placeholder="请输入店铺ID"
                clearable
                style="width: 240px"
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="创建时间">
              <el-date-picker
                v-model="dateRange"
                style="width: 240px"
                value-format="yyyy-MM-dd"
                type="daterange"
                range-separator="-"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
              ></el-date-picker>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
              <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
          </el-form>
        </template>

        <!-- 按钮操作栏 -->
        <template>
          <el-row :gutter="10" class="mb8">
            <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
          </el-row>
        </template>

        <!-- 表格 -->
        <template>
          <el-table v-loading="loading" :data="orderGoodsList" @selection-change="handleSelectionChange" @sort-change="handleSortChange">
            <el-table-column type="selection" width="50" align="center" />
            <el-table-column label="订单编号" align="center" key="orderNo" prop="orderNo" width="250" />
            <el-table-column label="客户" align="center" key="orderUserId" prop="orderUserId" :show-overflow-tooltip="true" width="120" >
              <template slot-scope="scope">
                <div class="flex-align-center" v-if="scope.row.customerUser">
                  <el-avatar shape="circle" size="medium" :src="scope.row.customerUser.avatar" alt="404"></el-avatar>
                  <div class="mgl5 font-14">{{scope.row.customerUser.nickName}}</div>
                </div>
                <div v-else>-</div>
              </template>
            </el-table-column>
            <el-table-column label="接单店员" align="center" key="employeeUserId" prop="employeeUserId" :show-overflow-tooltip="true" min-width="180" >
              <template slot-scope="scope">
                <div class="flex-align-center" v-if="scope.row.employeeUser">
                  <el-avatar shape="circle" size="medium" :src="scope.row.employeeUser.avatar" alt="404"></el-avatar>
                  <div class="mgl5 font-14">{{scope.row.employeeUser.nickName}}</div>
                </div>
                <div v-else>-</div>
              </template>
            </el-table-column>
            <el-table-column label="服务项目" align="center" key="goodsProjectId" prop="goodsProjectId" :show-overflow-tooltip="true">
              <template slot-scope="scope">
                <span>{{ COMMONFUNC.getLabelByValueOfArr(projectList, scope.row.goodsProjectId, 'projectId', 'projectTitle') }}</span>
              </template>
            </el-table-column>
            <el-table-column label="服务规格" align="center" key="goodsUnitId" prop="goodsUnitId" :show-overflow-tooltip="true">
              <template slot-scope="scope">
                <span>{{ COMMONFUNC.getLabelByValueOfArr(unitList, scope.row.goodsUnitId, 'unitId', 'unitTitle') }}</span>
              </template>
            </el-table-column>
            <el-table-column label="交易状态" align="center" key="payStatus" prop="payStatus" :show-overflow-tooltip="true" width="110">
              <template slot-scope="scope">
                <dict-tag :options="dict.type.app_pay_status" :value="scope.row.payStatus"/>
              </template>
            </el-table-column>
            <el-table-column label="服务状态" align="center" key="status" :show-overflow-tooltip="true" >
              <template slot-scope="scope">
                <dict-tag :options="dict.type.app_order_status" :value="scope.row.status"/>
              </template>
            </el-table-column>
            <el-table-column label="实付金额" align="center" key="actualAmount" prop="actualAmount" :show-overflow-tooltip="true" />
            <el-table-column label="下单金额" align="center" key="initAmount" prop="initAmount" :show-overflow-tooltip="true" />
            <el-table-column label="实际收益" align="center" key="finalAmount" prop="finalAmount" :show-overflow-tooltip="true" />
            <el-table-column label="分销提成" align="center" key="distributionAmount" prop="distributionAmount" :show-overflow-tooltip="true" />
            <el-table-column label="店员提成" align="center" key="employeeGetAmount" prop="employeeGetAmount" :show-overflow-tooltip="true" />
            <el-table-column label="优惠金额" align="center" key="discountAmount" prop="discountAmount" :show-overflow-tooltip="true" />
            <el-table-column label="单价" align="center" key="goodsPrice" prop="goodsPrice" :show-overflow-tooltip="true" />
            <el-table-column label="数量" align="center" key="goodsNum" prop="goodsNum" sortable="custom" :sort-orders="['descending', 'ascending']" :show-overflow-tooltip="true" />
            <el-table-column label="店员等级" align="center" key="goodsLevelId" prop="goodsLevelId" :show-overflow-tooltip="true">
              <template slot-scope="scope">
                <span>{{ COMMONFUNC.getLabelByValueOfArr(levelList, scope.row.goodsLevelId, 'levelId', 'levelTitle') }}</span>
              </template>
            </el-table-column>
            <el-table-column label="接单类型" align="center" key="acceptType" prop="acceptType" :show-overflow-tooltip="true">
              <template slot-scope="scope">
                <dict-tag :options="dict.type.app_accept_type" :value="scope.row.acceptType"/>
              </template>
            </el-table-column>
            <el-table-column label="排除店员" align="center" key="isExclude" prop="isExclude" :show-overflow-tooltip="true">
              <template slot-scope="scope">
                <dict-tag :options="dict.type.sys_yes_no" :value="scope.row.isExclude" :noType="true"/>
              </template>
            </el-table-column>
            <el-table-column label="是否已接单" align="center" key="isAccept" prop="isAccept" :show-overflow-tooltip="true" width="100">
              <template slot-scope="scope">
                <dict-tag :options="dict.type.sys_yes_no" :value="scope.row.isAccept" :noType="true"/>
              </template>
            </el-table-column>
            <el-table-column label="店员性别" align="center" key="sex" prop="sex" :show-overflow-tooltip="true">
              <template slot-scope="scope">
                <dict-tag :options="dict.type.sys_user_sex" :value="scope.row.sex" :noType="true"/>
              </template>
            </el-table-column>
            <el-table-column label="是否分销" align="center" key="isDistribution" prop="isDistribution" :show-overflow-tooltip="true">
              <template slot-scope="scope">
                <dict-tag :options="dict.type.sys_yes_no" :value="scope.row.isDistribution" :noType="true"/>
              </template>
            </el-table-column>
            <el-table-column label="支付方式" align="center" key="payType" width="120">
              <template slot-scope="scope">
                <dict-tag :noType="true" :options="dict.type.app_pay_type" :value="scope.row.payType"/>
              </template>
            </el-table-column>
            <el-table-column label="店铺名称" prop="shopInfo.shopName" min-width="120" v-if="$store.getters && $store.getters.admin" />
            <el-table-column label="创建时间" align="center" prop="createTime" sortable="custom" :sort-orders="['descending', 'ascending']" width="160">
              <template slot-scope="scope">
                <span>{{ parseTime(scope.row.createTime) }}</span>
              </template>
            </el-table-column>
            <el-table-column label="更新时间" align="center" prop="updateTime" sortable="custom" :sort-orders="['descending', 'ascending']" width="160">
              <template slot-scope="scope">
                <span>{{ parseTime(scope.row.updateTime) }}</span>
              </template>
            </el-table-column>
            <el-table-column
              label="操作"
              align="center"
              fixed="right"
              width="160"
              class-name="small-padding fixed-width"
            >
              <template slot-scope="scope">
                <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-view"
                  @click="handleView(scope.row,scope.index)"
                  v-hasPermi="['order:goods:list']"
                >详细</el-button>
                <el-dropdown size="mini" @command="(command) => handleCommand(command, scope.row)">
                  <el-button size="mini" type="text" icon="el-icon-d-arrow-right">更多</el-button>
                  <el-dropdown-menu slot="dropdown">
                    <el-dropdown-item command="handleOrderCancel" icon="el-icon-close" v-if="scope.row.status === 'wait_service' && scope.row.payStatus === 'paid'">取消订单</el-dropdown-item>
                    <el-dropdown-item command="handleOrderReset" icon="el-icon-key" v-if="scope.row.status === 'wait_service' && scope.row.payStatus === 'paid'">释放订单</el-dropdown-item>
                    <el-dropdown-item command="handleOrderStart" icon="el-icon-refresh" v-if="scope.row.status === 'wait_service' && scope.row.payStatus === 'paid'">开始服务</el-dropdown-item>
                    <el-dropdown-item command="handleOrderFinish" icon="el-icon-finished" v-if="scope.row.status === 'in_service' && scope.row.payStatus === 'paid'">完成订单</el-dropdown-item>
                    <el-dropdown-item command="handleOrderComment" icon="el-icon-edit" v-if="scope.row.status === 'finish_service' && scope.row.payStatus === 'paid' && scope.row.isRate === 'N'">订单评价</el-dropdown-item>
                    <el-dropdown-item command="handleDelete" icon="el-icon-delete">删除订单</el-dropdown-item>
                  </el-dropdown-menu>
                </el-dropdown>
              </template>
            </el-table-column>
          </el-table>
          <!-- 分页 -->
          <pagination
            v-show="total>0"
            :total="total"
            :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize"
            @pagination="getList"
          />
        </template>

      </el-col>
    </el-row>

    <!-- 弹窗 -->
    <template>
      <!-- 添加或修改订单配置对话框 -->
      <el-dialog :title="title" :visible.sync="open" width="1000px" :close-on-click-modal="false" append-to-body>
        <el-form ref="form" :model="form" :rules="rules" label-width="125px">
          <el-row>
            <el-col :span="12" v-if="form.customerUser">
              <el-form-item label="下单客户">
                <div class="flex-align-center">
                  <el-avatar shape="circle" size="medium" :src="form.customerUser.avatar" alt="404"></el-avatar>
                  <div class="mgl5 font-14">{{form.customerUser.nickName}}</div>
                </div>
              </el-form-item>
            </el-col>
            <el-col :span="12" v-if="form.employeeUser">
              <el-form-item label="接单店员">
                <div class="flex-align-center">
                  <el-avatar shape="circle" size="medium" :src="form.employeeUser.avatar" alt="404"></el-avatar>
                  <div class="mgl5 font-14">{{form.employeeUser.nickName}}</div>
                </div>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="客户微信Id">{{ form.wxId }}</el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="店员等级">{{ COMMONFUNC.getLabelByValueOfArr(levelList, form.goodsLevelId, 'levelId', 'levelTitle') }}</el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="服务项目">{{ COMMONFUNC.getLabelByValueOfArr(projectList, form.goodsProjectId, 'projectId', 'projectTitle') }}</el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="服务规格">{{ COMMONFUNC.getLabelByValueOfArr(unitList, form.goodsUnitId, 'unitId', 'unitTitle') }}</el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="下单金额">{{ form.initAmount }}</el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="实付金额">{{ form.actualAmount }}</el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="接单类型">
                <dict-tag :options="dict.type.app_accept_type" :value="form.acceptType"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="店员性别">
                <dict-tag :options="dict.type.sys_user_sex" :value="form.sex" :noType="true"/>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="客户备注">{{ form.remark }}</el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="订单开始时间">{{ parseTime(form.startTime) }}</el-form-item>
              <el-form-item label="订单结束时间">{{ parseTime(form.endTime) }}</el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="超时订单取消时间">{{ parseTime(form.overtimeCancelTime) }}</el-form-item>
              <el-form-item label="超时订单提醒时间">{{ parseTime(form.overtimeNoticeTime) }}</el-form-item>
            </el-col>
            <el-col :span="12" v-if="form.cancelType">
              <el-form-item label="取消原因">
                <div v-if="form.cancelType === 'customer'">客户主动取消</div>
                <div v-else-if="form.cancelType === 'employee'">店员主动取消</div>
                <div v-else-if="form.cancelType === 'system'">后台取消</div>
                <div v-else-if="form.cancelType === 'overtime'">超时未结单取消</div>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="是否超时提醒">
                <div v-if="form.isOvertimeNotice === 'Y'">是</div>
                <div v-else-if="form.isOvertimeNotice === 'N'">否</div>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </el-dialog>
    </template>

    <!-- 弹窗 -->
    <template>
      <!-- 添加或修改轮播图配置对话框 -->
      <el-dialog title="订单评价" :visible.sync="openComment" width="800px" :close-on-click-modal="false" append-to-body>
        <el-form ref="formComment" :model="formComment" :rules="rulesComment" label-width="100px">
          <el-row>
            <el-col :span="24">
              <el-form-item label="内容" prop="commentContent">
                <el-input v-model="formComment.commentContent" type="textarea" placeholder="请输入内容" maxlength="30" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="评分" prop="commentRate">
                <el-rate v-model="formComment.commentRate" style="padding-top: 7px;"></el-rate>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="是否匿名" prop="isAnonymous">
                <el-radio-group v-model="formComment.isAnonymous">
                  <el-radio
                    v-for="dict in dict.type.sys_yes_no"
                    :key="dict.value"
                    :label="dict.value"
                  >{{dict.label}}</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="24">
              <el-form-item label="备注">
                <el-input v-model="formComment.remark" type="textarea" placeholder="请输入内容"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="primary" @click="submitFormComment">确 定</el-button>
          <el-button @click="cancelComment">取 消</el-button>
        </div>
      </el-dialog>
    </template>
  </div>
</template>

<script>
import { listOrderGoods, getOrderGoods, delOrderGoods, addOrderGoods, updateOrderGoods, finishOrderGoods, changeOrderGoodsStatus, adminCancelOrderGoods } from "@/api/order/goods";
import { orderCommentCreate } from "@/api/order/comment";
import { listUnit } from "@/api/market/unit";
import { listLevel } from "@/api/market/level";
import { listProject } from "@/api/market/project";
import { getToken } from "@/utils/auth";

export default {
  name: "OrderGoods",
  dicts: ['sys_normal_disable', 'sys_user_sex', 'app_order_status', 'app_accept_type', 'sys_yes_no', 'app_pay_status', 'app_pay_type'],
  components: { },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 订单表格数据
      orderGoodsList: null,
      // 等级表格数据
      levelList: null,
      // 单位表格数据
      unitList: null,
      // 服务项目表格数据
      projectList: null,
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 是否显示弹出层
      openComment: false,
      // 默认密码
      initPassword: undefined,
      // 日期范围
      dateRange: [],
      // 表单参数
      form: {},
      // 表单参数
      formComment: {},
      defaultProps: {
        children: "children",
        label: "label"
      },
      // 订单导入参数
      upload: {
        // 是否显示弹出层（订单导入）
        open: false,
        // 弹出层标题（订单导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的订单数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/orderGoods/orderGoods/importData"
      },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        goodsTitle: undefined,
        status: undefined,
        payStatus: undefined,
        isRate: undefined,
        isAccept: undefined,
        orderNo: undefined,
        acceptType: undefined,
        goodsLevelId: undefined,
        goodsUnitId: undefined,
        goodsProjectId: undefined,
        isExclude: undefined,
        isDistribution: undefined,
        shopId: undefined,
        orderByColumn: 'createTime',
        isAsc: 'descending',
      },
      // 表单校验
      rules: {
        goodsTitle: [
          { required: true, message: "订单名称不能为空", trigger: "blur" },
          { min: 2, max: 20, message: '订单名称长度必须介于 2 和 20 之间', trigger: 'blur' }
        ]
      },
      // 表单校验
      rulesComment: {
        commentContent: [
          { required: true, message: "内容不能为空", trigger: "blur" },
        ],
        commentRate: [
          { required: true, message: "评分不能为空", trigger: "blur" },
        ],
      }
    };
  },
  watch: {
  },
  created() {
    Promise.all([this.getLevelList(), this.getUnitList(), this.getProjectList()]).then((values) => {
        this.getList();
      });
  },
  methods: {
    /** 查询订单列表 */
    getList() {
      this.loading = true;
      listOrderGoods(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
          this.orderGoodsList = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      );
    },
    /** 查询等级列表 */
    getLevelList() {
      let that = this;
      return new Promise((resolve, reject)=>{
        listLevel(this.addDateRange({ pageNum: 1, pageSize: 10000, orderByColumn: 'levelSort', isAsc: 'ascending',}, null)).then(response => {
          that.levelList = response.rows;
          resolve(that.levelList)
        });
      })
    },
    /** 查询单位列表 */
    getUnitList() {
      let that = this;
      return new Promise((resolve, reject)=>{
        listUnit(this.addDateRange({ pageNum: 1, pageSize: 10000, }, null)).then(response => {
          that.unitList = response.rows;
          resolve(that.unitList)
        });
      })
    },
    /** 查询项目列表 */
    getProjectList() {
      let that = this;
      return new Promise((resolve, reject)=>{
        listProject(this.addDateRange({ pageNum: 1, pageSize: 10000, }, null)).then(response => {
          that.projectList = response.rows;
          resolve(that.projectList)
        });
      })
    },
    // 订单状态修改
    handleStatusChange(row) {
      let text = row.status === "0" ? "启用" : "停用";
      this.$modal.confirm('确认要"' + text + '""' + row.goodsTitle + '"订单吗？').then(function() {
        return changeOrderGoodsStatus(row.orderNo, row.status);
      }).then(() => {
        this.$modal.msgSuccess(text + "成功");
      }).catch(function() {
        row.status = row.status === "0" ? "1" : "0";
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        orderNo: undefined,
        orderGoodsPrice: undefined,
        orderGoodsPriceNight: undefined,
        goodsTitle: undefined,
        goodsLevelId: undefined,
        goodsUnitId: undefined,
        goodsProjectId: undefined,
        isExclude: undefined,
        status: "0",
        remark: undefined,
      };
      this.resetForm("form");
    },
    // 取消按钮
    cancelComment() {
      this.openComment = false;
      this.resetComment();
    },
    // 表单重置
    resetComment() {
      this.formComment = {
        orderNo: undefined,
        commentContent: undefined,
        commentRate: undefined,
        isAnonymous: "N",
        status: "approve",
        remark: undefined,
      };
      this.resetForm("formComment");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.queryParams.deptId = undefined;
      this.$refs.tree.setCurrentKey(null);
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.orderNo);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      getOrderGoods().then(response => {
        this.open = true;
        this.title = "添加订单";
        this.form.password = this.initPassword;
      });
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const orderNo = row.orderNo || this.ids;
      getOrderGoods(orderNo).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改订单";
      });
    },
    /** 排序触发事件 */
    handleSortChange(column, prop, order) {
      this.queryParams.orderByColumn = column.prop;
      this.queryParams.isAsc = column.order;
      this.getList();
    },
    /** 提交按钮 */
    submitForm: function() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          let params = JSON.parse(JSON.stringify(this.form))
          if (this.form.orderNo != undefined) {
            updateOrderGoods(params).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addOrderGoods(params).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    
    /** 提交按钮 */
    submitFormComment: function() {
      this.$refs["formComment"].validate(valid => {
        if (valid) {
          let params = JSON.parse(JSON.stringify(this.formComment))
          orderCommentCreate(params).then(response => {
            this.$modal.msgSuccess("评价成功");
            this.openComment = false;
            this.getList();
          });
        }
      });
    },
    /** 详细按钮操作 */
    handleView(row) {
      this.open = true;
      this.form = row;
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const orderNos = row.orderNo || this.ids;
      this.$modal.confirm('是否确认删除订单编号为"' + orderNos + '"的数据项？').then(function() {
        return delOrderGoods(orderNos);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('orderGoods/orderGoods/export', {
        ...this.queryParams
      }, `orderGoods_${new Date().getTime()}.xlsx`)
    },
    // 更多操作触发
    handleCommand(command, row) {
      switch (command) {
        case "handleOrderCancel":
          this.handleOrderCancel(row);
          break;
        case "handleOrderReset":
          this.handleOrderReset(row);
          break;
        case "handleOrderStart":
          this.handleOrderStart(row);
          break;
        case "handleOrderFinish":
          this.handleOrderFinish(row);
        case "handleOrderComment":
          this.handleOrderComment(row);
          break;
        case "handleDelete":
          this.handleDelete(row);
          break;
        default:
          break;
      }
    },
    /** 取消按钮操作 */
    handleOrderCancel(row) {
      const orderNos = row.orderNo || this.ids;
      this.$modal.confirm('是否确认取消订单编号为"' + orderNos + '"的数据项？').then(function() {
        let params = {
          orderNo: orderNos
        }
        return adminCancelOrderGoods(params);
      }).then(() => {
        setTimeout(()=>{
          this.$modal.msgSuccess("取消成功");
          this.getList();
        }, 300)
      }).catch(() => {});
    },
    /** 重置按钮操作 */
    handleOrderReset(row) {
      const orderNos = row.orderNo || this.ids;
      this.$modal.confirm('释放订单后，订单将会进入抢单大厅，是否确认释放订单编号为"' + orderNos + '"的数据项？').then(function() {
        // 接单类型（0-指定店员 1-盲盒下单 2-体验下单 3-转让单）
        row.acceptType = "3";
        row.employeeUserId = null;
        row.isAccept = "N";
        return updateOrderGoods(row);
      }).then(() => {
        setTimeout(()=>{
          this.$modal.msgSuccess("重置成功");
          this.getList();
        }, 300)
      }).catch(() => {});
    },
    /** 开始服务按钮操作 */
    handleOrderStart(row) {
      const orderNos = row.orderNo || this.ids;
      this.$modal.confirm('是否确认开始服务订单编号为"' + orderNos + '"的数据项？').then(function() {
        row.status = "in_service";
        return updateOrderGoods(row);
      }).then(() => {
        setTimeout(()=>{
          this.$modal.msgSuccess("已开始");
          this.getList();
        }, 300)
      }).catch(() => {});
    },
    /** 完成服务按钮操作 */
    handleOrderFinish(row) {
      const orderNos = row.orderNo || this.ids;
      this.$modal.confirm('是否确认完成服务订单编号为"' + orderNos + '"的数据项？').then(function() {
        row.status = "finish_service";
        return finishOrderGoods(row);
      }).then(() => {
        setTimeout(()=>{
          this.$modal.msgSuccess("已完成");
          this.getList();
        }, 300)
      }).catch(() => {});
    },
    /** 订单评价按钮操作 */
    handleOrderComment(row) {
      if(row.status === 'finisn_service'){
        this.resetComment();
        const orderNos = row.orderNo || this.ids;
        this.formComment.orderNo = orderNos
        this.openComment = true
      }
    },
  }
};
</script>
